
#ifndef __RSA_PUBLIC_KEY_H
#define __RSA_PUBLIC_KEY_H

#include <openssl/rsa.h>
#include "../iface/SSLInterface.h"
#include "PublicKey.h"
#include "EncryptionKey.h"
#include "CheckingKey.h"

/** An class encapsulating an RSA public key. */
class RSAPublicKey : public PublicKey, public EncryptionKey, public CheckingKey
{
   public:
      RSAPublicKey();
      RSAPublicKey(const char *name);
      // Construct a duplicate of the public key
      RSAPublicKey(const RSAPublicKey &other);
      // Construct from PEM format
      RSAPublicKey(const char *pemtext, const char *name);
      // Construct from OpenSSL format
      RSAPublicKey(RSA *pubkey, const char *name);
      // Copy assignment operator
      RSAPublicKey &operator=(const RSAPublicKey &other);
      // Destroy public key
      ~RSAPublicKey();
      // Get new OpenSSL RSA object
      int getSSLKeyComponents(RSA **pubkey) const;
      // Get PEM data
      int getPEMKeyData(char **pemtext, const char *password) const;
      // Get OpenSSH binary blob
      int getSSHKeyBlob(char **blob, int *reallength) const;
      // Get OpenSSH text with key label
      int getSSHKeyBlob(char **textblob, const char *keylabel) const;
      // Compare key to key
      int compareKeyEqual(PublicKey *pubkey) const;
      // Get key type name
      static const keytypetype getStaticKeyType() { return KEY_TYPE_PUBLIC_RSA; }
      const keytypetype getKeyType() const { return KEY_TYPE_PUBLIC_RSA; }
      // General import key function that others call.
      int importPublicKeyWithOptionalPassword(const char *pemtext, const char *password);
      // To import from text - Base64 RAW or PEM
      int importKeyFromASCII(const char *text, const char *name);
      // To export to text - Base64 RAW or PEM
      int exportKeyToASCII(char **text) const;
      // Import from text with password
      int importKeyFromASCIIWithPassword(const char *text, const char *password, const char *name);
      // Export to text with password
      int exportKeyToASCIIWithPassword(char **text, const char *password) const;
   private:
      static int copyRSASSLPublicKey(RSA *dst, RSA *src);
      /** A pointer to the real RSA public key, held in SSL format. */
      RSA *key;
};

#endif
